<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<link rel="stylesheet" data-name="vs/editor/editor.main"
      href="/com/monaco/node_modules/monaco-editor-core/dev/vs/editor/editor.main.css">
<script src="/com/monaco/node_modules/monaco-editor-core/dev/vs/loader.js"></script>
<script src="/com/monaco/node_modules/monaco-editor-core/dev/vs/editor/editor.main.nls.js"></script>
<script src="/com/monaco/node_modules/monaco-editor-core/dev/vs/editor/editor.main.js"></script>
<style>
    .monaco-editor.vs .view-overlays .current-line {
        border: 0px !important;
    }

    .overflow-guard {
        border: 1px solid #d2d2d2;
    }

    /* #content div{
         margin-bottom:20px;
     }*/
</style>
<div class="bjui-pageContent" style="top: 0px; bottom: 32px;">
    <form id="quartz_job_form_id" method="post" action="/admin/plan/task/save">
        <div class="bjui-row col-2">
            <input type="hidden" name="id" value="${saveQuartzJob.id}">
            <input type="hidden" name="script" id="script_cl" value="${saveQuartzJob.script}">
            <label class="row-label">任务名称</label>
            <div class="row-input">
                <input type="text" name="name" value="${saveQuartzJob.name}" data-rule="required">
            </div>

            <%--<p>--%>
            <%--<label class="row-label">标识</label>--%>
            <%--<span class="datagrid-dialog-column-span">--%>
            <%--<input type="text" name="nid" value="${saveQuartzJob.nid}" data-rule="required">--%>
            <%--</span>--%>
            <%--</p>--%>
            <label class="row-label">cron表达式</label>
            <div class="row-input">
                <input type="text" name="cron" value="${saveQuartzJob.cron}" data-rule="required">
            </div>

            <%--<label class="row-label">开关</label>
            <div class="row-input">
                <select data-toggle="enabled" name="enabled">
                    <option value="true"
                            <c:if test="${empty saveQuartzJob.enabled || saveQuartzJob.enabled}">selected="selected"</c:if> >
                        开
                    </option>
                    <option value="false"
                            <c:if test="${!empty saveQuartzJob.enabled  && !saveQuartzJob.enabled}">selected="selected"</c:if> >
                        关
                    </option>
                </select>
            </div>--%>
            <%--script--%>
            <p><label class="row-label">执行脚本</label></p>
            <div class="row-input">
                <div id="content">
                    <div>
                        <div class="bottom">
                            <div class="one" id="container" style="width: 860px;height: 500px;">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li>
            <button type="button" class="btn btn-red cancel" onclick="BJUI.dialog('closeCurrent');" data-icon="remove">
                <i class="fa fa-remove"></i> 取消
            </button>
        </li>
        <li>
            <button type="button" class="btn btn-default save" onclick="planTaskSave();" data-icon="save"><i
                    class="fa fa-save"></i> 保存
            </button>
        </li>
    </ul>
</div>
<script>
    var defaultClass = '${defaultClass}' || '{saveQuartzJob.script}';
    var editor={};
    $(function () {
        editor = monaco.editor.create(document.getElementById('container'), {
            value: [
                defaultClass
            ].join('\n'),
            language: 'java'
        });
    });

    /**
     * 提交保存信息
     */
    function planTaskSave() {
        var content = editor.getValue();
        $("#script_cl").val(content);
        BJUI.ajax('ajaxform', {
            url: '/quartz/save',
            form: $("#quartz_job_form_id"),
            validate: true,
            loadingmask: true,
            callback: function (response, options) {
                BJUI.dialog('closeCurrent');
                if (response.haveError) {
                    BJUI.alertmsg('error', response.errMsg, {
                        okCall: function () {
                            BJUI.navtab('refresh')
                        }
                    });

                } else {
                    BJUI.alertmsg('ok', response.data, {
                        okCall: function () {
                            BJUI.navtab('refresh')
                        }
                    });
                }
            }
        });
    }
</script>